<template>
	<view class="content">
		<image src="../../../static/images/work1.jpg" mode="" class="img_bg"></image>
		<view class="guanzhu">
		<button type="default" @click="guanZhu" :disabled="change">{{button}}</button>
		<text>温馨提示：请先绑定，然后关注下方安全智慧云平台公众号</text>
		</view>
		<image src="../../../static/images/erweima.jpg" show-menu-by-longpress="true" style="width: 500rpx; margin-top: 200rpx; margin-left: 15%;"></image>
		<view style="color: #FFFFFF; margin-left: 5%;">
			可先长按保存图片,然后使用微信扫一扫打开识别
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid:'',
				token:'',
				wxcode:'',
				button:'推送绑定',
				change:false,
			}
		},
		onLoad() {
			this.uid = uni.getStorageSync("user").uid;
			this.token = uni.getStorageSync("user").token;
			let that = this
			// 获取微信code
			// #ifdef MP-WEIXIN
			uni.login({
				success(res){
					that.wxcode = res.code
				}
			})
			// #endif
		},
		onShow() {
			this.isBing()
		},
		methods: {
			// 进入页面时判断是否绑定成功
			isBing(){
				let that = this
				uni.request({
					url: 'https://aqmore.sxpz.vip/AppApi/WeiXin/is_bing?uid=' + this.uid + '&token=' + this.token,
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
						},
						success(res) {
							if(res.data.code == 200){
								that.button = '推送已绑定'
								that.change = true
							}
						}
				})
				
			},
			// 点击绑定
			guanZhu(){
				let that = this
				uni.request({
					url: 'https://aqmore.sxpz.vip/AppApi/WeiXin/bing?uid=' + this.uid + '&token=' + this.token + '&code=' + this.wxcode,
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success:function(res){
						if(res.data.code == 200){
							that.button = '推送已绑定'
							that.change = true
							uni.showToast({
								title:'绑定成功',
								icon:'none'
							})
							
						}else{
							uni.showToast({
								title:'绑定失败',
								icon:'none'
							})
						}
					}
					})
			
			}
		}
	}
</script>

<style>
	page {
		margin: 0;
		top: 0;
		height: 100%;
		width: 100%;
		/* background-color: #FFFFFF; */
	}
	
	.content {
		margin: 0;
		padding: 0;
		height: 100%;
		width: 100%;
	}
	.guanzhu{
		text-align: center;
		color: #FFFFFF;
		font-size: 20px;
	}
</style>
